********************************************************************************
** 	TITLE:		pooled_district_contact_networks                              ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       Various election studies                                      **
**  DATE:	    October 2022 						                          **	
**  VERSION:	Stata 16		                                              **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "pooled_district_contact_networks", replace

* Open dataset

use "merge_contact_networks_full.dta", clear

* Identify US state presidential elections

gen stelec = 1 if strpos(study_id, "ANES-S") > 0

keep if strpos(study_id, "-D") > 0
drop if strpos(study_id, "-DEM-P") > 0

* Standardized knowledge

egen study_group = group(study_id)
sort study_group
by study_group: egen knowledge_mean = mean(knowledge)
by study_group: egen knowledge_sd  = sd(knowledge)
by study_group: gen  knowledge_std = (knowledge - knowledge_mean)/knowledge_sd


*******************************
** COMPETITIVENESS: DISTRICT **
*******************************

* Bare-bones models for competitiveness

eststo: mixed forecast enep_d time i.wishful_3pts if stelec!=1 || region: || district_name: || study_id: , mle var
estimates store m1

eststo: mixed forecast margin_d time i.wishful_3pts if stelec!=1 || region: || district_name: || study_id: , mle var
estimates store m2

label variable forecast " "

esttab using "pooled_competitiveness_d.tex", wide refcat(enep_d "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("ENEP" "Vote margin") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" enep_d "\hspace{1em} ENEP" margin_d "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference") title("Competitiveness and citizens' forecasting ability, district-level expectations") order(1.wishful_3pts 2.wishful_3pts 3.wishful_3pts time enep_d margin_d) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Predictive margins for ENEP

estimates restore m1

qui margins, at(enep_d=(1(1)7))

marginsplot, recast(line) recastci(rline) ciopts(lpat(dash) col(black)) ylabel(0(.2)1, labsize(medium) nogrid angle(horizontal) format(%5.1f)) plotopts(lcolor(black) mcolor(black)) xlabel(1(1)7, labsize(medium)) xtitle("Margin of victory", size(medium) margin(t=5)) ytitle("Linear prediction", size(medium) margin(r=5)) title("") graphregion(color(white)) legend(off) saving("margin_d.gph", replace)

* Predictive margins for margin of victory

estimates restore m2

margins, at(margin_d=0) atmeans
margins, at(margin_d=30) atmeans

estimates restore m2

qui margins, at(margin_d=(0(2)30))

marginsplot, recast(line) recastci(rline) ciopts(lpat(dash) col(black)) ylabel(0(.2)1, labsize(medium) nogrid angle(horizontal) format(%5.1f)) plotopts(lcolor(black) mcolor(black)) xlabel(0(5)30, labsize(medium)) xtitle("Margin of victory", size(medium) margin(t=5)) ytitle("Linear prediction", size(medium) margin(r=5)) title("") graphregion(color(white)) legend(off) saving("margin_d.gph", replace)


*************************************************
** INTERACTIONS WITH COMPETITIVENESS: DISTRICT **
*************************************************

* Wishful thinking and competitiveness

eststo: mixed forecast i.wishful_3pts##c.margin_d i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.wishful_3pts || study_id: , mle var

label variable forecast " "

esttab using "pooled_wishful_margin_d.tex", wide drop(0.postsecondary 0.male 1.wishful_3pts#c.margin_d) refcat(margin_d "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 2.wishful_3pts#c.margin_d "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Wishful thinking") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_d "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 2.wishful_3pts#c.margin_d "\hspace{1em} No preference $\times$ Margin" 3.wishful_3pts#c.margin_d "\hspace{1em} Winner preference $\times$ Margin") title("\textit{Wishful thinking $\times$ Margin of victory} interaction, district-level expectations") order(1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_d 2.wishful_3pts#c.margin_d 3.wishful_3pts#c.margin_d 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Discussion and competitiveness

eststo: mixed forecast i.discussion_3pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.discussion_3pts || study_id: , mle var

label variable forecast " "

esttab using "pooled_discussion_margin_d.tex", wide drop(0.postsecondary 0.male 0.discussion_3pts#c.margin_d) refcat(margin_d "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.discussion_3pts "\textbf{\textit{Political discussion}}" 1.discussion_3pts#c.margin_d "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Discussion") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_d "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.discussion_3pts "\hspace{1em} Low (R)" 1.discussion_3pts "\hspace{1em} Medium" 2.discussion_3pts "\hspace{1em} High" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 1.discussion_3pts#c.margin_d "\hspace{1em} Medium $\times$ Margin" 2.discussion_3pts#c.margin_d "\hspace{1em} High $\times$ Margin") title("\textit{Political discussion $\times$ Margin of victory} interaction, district-level expectations") order(0.discussion_3pts 1.discussion_3pts 2.discussion_3pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_d 1.discussion_3pts#c.margin_d 2.discussion_3pts#c.margin_d 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Disagreement and competitiveness

eststo: mixed forecast i.disagreement_3pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.disagreement_3pts || study_id: , mle var

label variable forecast " "

esttab using "pooled_disagreement_margin_d.tex", wide drop(0.postsecondary 0.male 0.disagreement_3pts#c.margin_d) refcat(margin_d "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.disagreement_3pts "\textbf{\textit{Disagreement}}" 1.disagreement_3pts#c.margin_d "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Disagreement") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_d "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.disagreement_3pts "\hspace{1em} Low (R)" 1.disagreement_3pts "\hspace{1em} Medium" 2.disagreement_3pts "\hspace{1em} High" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 1.disagreement_3pts#c.margin_d "\hspace{1em} Medium $\times$ Margin" 2.disagreement_3pts#c.margin_d "\hspace{1em} High $\times$ Margin") title("\textit{Disagreement $\times$ Margin of victory} interaction, district-level expectations") order(0.disagreement_3pts 1.disagreement_3pts 2.disagreement_3pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_d 1.disagreement_3pts#c.margin_d 2.disagreement_3pts#c.margin_d 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Network size and competitiveness

eststo: mixed forecast i.size_3pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.size_3pts || study_id: , mle var

label variable forecast " "

esttab using "pooled_size_margin_d.tex", wide drop(0.postsecondary 0.male 0.size_3pts#c.margin_d) refcat(margin_d "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" 0.size_3pts "\textbf{\textit{Network size}}" 1.size_3pts#c.margin_d "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Network size") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_d "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" 0.size_3pts "\hspace{1em} Small (R)" 1.size_3pts "\hspace{1em} Medium" 2.size_3pts "\hspace{1em} Large" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" 1.size_3pts#c.margin_d "\hspace{1em} Medium $\times$ Margin" 2.size_3pts#c.margin_d "\hspace{1em} Large $\times$ Margin") title("\textit{Network size $\times$ Margin of victory} interaction, district-level expectations") order(0.size_3pts 1.size_3pts 2.size_3pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_d 1.size_3pts#c.margin_d 2.size_3pts#c.margin_d 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

* Network expertise and competitiveness

eststo: mixed forecast c.expertise_4pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: expertise_4pts || study_id: , mle var

label variable forecast " "

esttab using "pooled_expertise_margin_d.tex", wide drop(0.postsecondary 0.male) refcat(margin_d "\textbf{\textit{Competitiveness}}" time "\textbf{\textit{Time control}}" 1.wishful_3pts "\textbf{\textit{Wishful thinking}}" expertise_4pts "\textbf{\textit{Network expertise}}" c.expertise_4pts#c.margin_d "\textbf{\textit{Interaction}}" 1.postsecondary "\textbf{\textit{Sociodemographics}}", nolabel) se width(\hsize) b(2) se(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Network expertise") interaction("$\times$")style(tex) replace booktabs varlabels(_cons "\textbf{\textit{Constant}}" margin_d "\hspace{1em} Vote margin" time "\hspace{1em} Days before election" 1.wishful_3pts "\hspace{1em} Loser preference (R)" 2.wishful_3pts "\hspace{1em} No preference" 3.wishful_3pts "\hspace{1em} Winner preference" expertise_4pts "\hspace{1em} Expertise" 1.postsecondary "\hspace{1em} Postsecondary" age2 "\hspace{1em} Age" 1.male "\hspace{1em} Male" c.expertise_4pts#c.margin_d "\hspace{1em} Expertise $\times$ Margin") title("\textit{Network expertise $\times$ Margin of victory} interaction, district-level expectations") order(expertise_4pts 1.wishful_3pts 2.wishful_3pts 3.wishful_3pts margin_d c.expertise_4pts#c.margin_d 1.postsecondary age2 1.male time) stats(N, labels("\textit{N} observations") fmt(%9.0fc)) nonotes addnotes("\textit{Note}. Standard errors in parentheses. R = Reference category." "Significance levels: + \textit{p} $<$ 0.10; * \textit{p} $<$ 0.05; ** \textit{p} $<$ 0.01; *** \textit{p} $<$ 0.001.")

eststo clear

*******************************************************************************************
** Interaction of wishful thinking and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.wishful_3pts##c.margin_d i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.wishful_3pts || study_id: , mle var

mgen if wishful_3pts == 1, at(margin_d=(0(2)30)) stub(A) replace // Predictive margins for loser preference
mgen if wishful_3pts == 2, at(margin_d=(0(2)30)) stub(B) replace // Predictive margins for no preference
mgen if wishful_3pts == 3, at(margin_d=(0(2)30)) stub(C) replace // Predictive margins for winner preference

lab var Amargin "Loser preference" // Add labels for graph legend
lab var	Bmargin "No preference"
lab var	Cmargin "Winner preference"

gen ASig1 = Amargin // Create variable for significance information of group differences
gen BSig1 = Bmargin
gen CSig1 = Cmargin
lab var ASig1 "A"
lab var BSig1 "B"
lab var	CSig1 "C"

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig1 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig1 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Winner–Loser", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Winner preference" 4 "Loser preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("winner_loser_wishful_margin_d.gph", replace) // Winner vs Loser

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig1 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig1 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("Winner–None", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Winner preference" 4 "No preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("winner_no_wishful_margin_d.gph", replace) // Winner vs None

twoway (rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig1 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig1 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("None–Loser", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "No preference" 4 "Loser preference") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("no_loser_wishful_margin_d.gph", replace) // None vs Loser

graph combine winner_loser_wishful_margin_d.gph winner_no_wishful_margin_d.gph no_loser_wishful_margin_d.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("wishful_margin_d.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.wishful_3pts##c.margin_d i.postsecondary age2 i.male time if stelec!=1 & margin_d >= 0 & margin_d <= 5 || region: || district_name: R.wishful_3pts || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin1_d.gph", replace

mixed forecast i.wishful_3pts##c.margin_d i.postsecondary age2 i.male time if stelec!=1 & margin_d > 5 & margin_d <= 10 || region: || district_name: R.wishful_3pts || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin2_d.gph", replace

mixed forecast i.wishful_3pts##c.margin_d i.postsecondary age2 i.male time if stelec!=1 & margin_d > 10 & margin_d <= 15 || region: || district_name: R.wishful_3pts || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin3_d.gph", replace

mixed forecast i.wishful_3pts##c.margin_d i.postsecondary age2 i.male time if stelec!=1 & margin_d > 15 || region: || district_name: R.wishful_3pts || study_id: , mle var

margins, at(wishful_3pts=(1(1)3))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(1 "Loser" 2 "None" 3 "Winner", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "wishful_margin4_d.gph", replace

graph combine wishful_margin1_d.gph wishful_margin2_d.gph wishful_margin3_d.gph wishful_margin4_d.gph, row(2) saving("wishful_margin_1234_d.gph", replace)


*************************************************************************************
** Interaction of discussion and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.discussion_3pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.discussion_3pts || study_id: , mle var

mgen if discussion_3pts == 0, at(margin_d=(0(2)30)) stub(A) replace // Predictive margins for low discussion
mgen if discussion_3pts == 1, at(margin_d=(0(2)30)) stub(B) replace // Predictive margins for medium discussion
mgen if discussion_3pts == 2, at(margin_d=(0(2)30)) stub(C) replace // Predictive margins for high discussion

lab var Amargin "Low discussion" // Add labels for graph legend
lab var	Bmargin "Medium discussion"
lab var	Cmargin "High discussion"

gen ASig2 = Amargin // Create variable for significance information of group differences
gen BSig2 = Bmargin
gen CSig2 = Cmargin
lab var ASig2 "A"
lab var BSig2 "B"
lab var	CSig2 "C"

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig2 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig2 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("High–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High discussion" 4 "Low discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_low_discussion_margin_d.gph", replace) // High vs Low

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig2 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig2 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("High–Medium", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High discussion" 4 "Medium discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_medium_discussion_margin_d.gph", replace) // High vs Medium

twoway (rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig2 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig2 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Medium–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Medium discussion" 4 "Low discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("medium_low_discussion_margin_d.gph", replace) // Medium vs Low

graph combine high_low_discussion_margin_d.gph high_medium_discussion_margin_d.gph medium_low_discussion_margin_d.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("discussion_margin_d.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d >= 0 & margin_d <= 5 || region: || district_name: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin1_d.gph", replace

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 5 & margin_d <= 10 || region: || district_name: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin2_d.gph", replace

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 10 & margin_d <= 15 || region: || district_name: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin3_d.gph", replace

mixed forecast i.discussion_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 15 || region: || district_name: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_margin4_d.gph", replace

graph combine discussion_margin1_d.gph discussion_margin2_d.gph discussion_margin3_d.gph discussion_margin4_d.gph, row(2) saving("discussion_margin_1234_d.gph", replace)

* By partisan preference

mixed forecast i.discussion_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_wishful1_d.gph", replace

mixed forecast i.discussion_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_wishful2_d.gph", replace

mixed forecast i.discussion_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(discussion_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "discussion_wishful3_d.gph", replace

graph combine discussion_wishful1_d.gph discussion_wishful2_d.gph discussion_wishful3_d.gph, row(1) saving("discussion_wishful_123_d.gph", replace)

graph display, ysize(4) xsize(9)

***************************************************************************************
** Interaction of disagreement and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.disagreement_3pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.disagreement_3pts || study_id: , mle var

mgen if disagreement_3pts == 0, at(margin_d=(0(2)30)) stub(A) replace // Predictive margins for low disagreement
mgen if disagreement_3pts == 1, at(margin_d=(0(2)30)) stub(B) replace // Predictive margins for medium disagreement
mgen if disagreement_3pts == 2, at(margin_d=(0(2)30)) stub(C) replace // Predictive margins for high disagreement

lab var Amargin "Low disagreement" // Add labels for graph legend
lab var	Bmargin "Medium disagreement"
lab var	Cmargin "High disagreement"

gen ASig3 = Amargin // Create variable for significance information of group differences
gen BSig3 = Bmargin
gen CSig3 = Cmargin
lab var ASig3 "A"
lab var BSig3 "B"
lab var	CSig3 "C"

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig3 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig3 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("High–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High disagreement" 4 "Low disagreement") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_low_disagreement_margin_d.gph", replace) // High vs Low

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig3 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig3 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("High–Medium", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "High disagreement" 4 "Medium disagreement") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("high_medium_disagreement_margin_d.gph", replace) // High vs Medium

twoway (rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig3 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig3 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Medium–Low", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Medium disagreement" 4 "Low disagreement") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("medium_low_disagreement_margin_d.gph", replace) // Medium vs Low

graph combine high_low_disagreement_margin_d.gph high_medium_disagreement_margin_d.gph medium_low_disagreement_margin_d.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("disagreement_margin_d.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d >= 0 & margin_d <= 5 || region: || district_name: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin1_d.gph", replace

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 5 & margin_d <= 10 || region: || district_name: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin2_d.gph", replace

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 10 & margin_d <= 15 || region: || district_name: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin3_d.gph", replace

mixed forecast i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 15 || region: || district_name: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_margin4_d.gph", replace

graph combine disagreement_margin1_d.gph disagreement_margin2_d.gph disagreement_margin3_d.gph disagreement_margin4_d.gph, row(2) saving("disagreement_margin_1234_d.gph", replace)

* By partisan preference

mixed forecast i.disagreement_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_wishful1_d.gph", replace

mixed forecast i.disagreement_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_wishful2_d.gph", replace

mixed forecast i.disagreement_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(disagreement_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Low" 1 "Medium" 2 "High", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "disagreement_wishful3_d.gph", replace

graph combine disagreement_wishful1_d.gph disagreement_wishful2_d.gph disagreement_wishful3_d.gph, row(1) saving("disagreement_wishful_123_d.gph", replace)

graph display, ysize(4) xsize(9)

*******************************************************************************
** Interaction of size and margin of victory (Ordinal X Continuous interaction)

mixed forecast i.size_3pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: R.size_3pts || study_id: , mle var

mgen if size_3pts == 0, at(margin_d=(0(2)30)) stub(A) replace // Predictive margins for small network
mgen if size_3pts == 1, at(margin_d=(0(2)30)) stub(B) replace // Predictive margins for medium network
mgen if size_3pts == 2, at(margin_d=(0(2)30)) stub(C) replace // Predictive margins for large network

lab var Amargin "Small network" // Add labels for graph legend
lab var	Bmargin "Medium network"
lab var	Cmargin "Large network"

gen ASig4 = Amargin // Create variable for significance information of group differences
gen BSig4 = Bmargin
gen CSig4 = Cmargin
lab var ASig4 "A"
lab var BSig4 "B"
lab var	CSig4 "C"

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected CSig4 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected ASig4 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Large–Small", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Large" 4 "Small") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("large_small_size_margin_d.gph", replace) // Large vs Small

twoway (rline Cll Cul Cmargin_d, lcol(green%30) lwidth(thin) lpattern(dash))(rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(connected CSig4 Cmargin_d, lpattern(solid) lcolor(green) lwidth(medthick) msym(none))(connected BSig4 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none)), title("Large–Medium", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Large" 4 "Medium") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("large_medium_size_margin_d.gph", replace) // Large vs Medium

twoway (rline Bll Bul Bmargin_d, lcol(blue%30) lwidth(thin) lpattern(dash))(rline All Aul Amargin_d, lcol(red*1.2%30) lwidth(thin) lpattern(dash))(connected BSig4 Bmargin_d, lpattern(solid) lcolor(blue) lwidth(medthick) msym(none))(connected ASig4 Amargin_d, lpattern(solid) lcolor(red*1.2) lwidth(medthick) msym(none)), title("Medium–Small", box fcolor("gs14") bexpand nospan color(black) size(vhuge)) xtitle("") xlabel(minmax, labsize(vhuge) format(%3.0f)) xmticks(minmax, tlength(scheme tick)) ylabel(0 1, labsize(vhuge) nogrid angle(horizontal) format(%5.0f)) graphregion(color(white)) plotregion(lcolor(black) lwidth(thin)) legend(order(3 "Medium discussion" 4 "Small discussion") pos(6) col(1) size(huge) symxsize(8) region(lstyle(none))) legend(off) saving("medium_small_size_margin_d.gph", replace) // Medium vs Small

graph combine large_small_size_margin_d.gph large_medium_size_margin_d.gph medium_small_size_margin_d.gph, l1("Linear prediction", size(huge)) b1("Margin of victory", size(huge) margin(l=9)) row(1) saving("size_margin_d.gph", replace)

graph display, ysize(4) xsize(12)

* By level of margin

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d >= 0 & margin_d <= 5 || region: || district_name: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin1_d.gph", replace

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 5 & margin_d <= 10 || region: || district_name: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin2_d.gph", replace

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 10 & margin_d <= 15 || region: || district_name: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin3_d.gph", replace

mixed forecast i.size_3pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 15 || region: || district_name: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(medlarge)) ylabel(0 1, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_margin4_d.gph", replace

graph combine size_margin1_d.gph size_margin2_d.gph size_margin3_d.gph size_margin4_d.gph, row(2) saving("size_margin_1234_d.gph", replace)

* By partisan preference

mixed forecast i.size_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_wishful1_d.gph", replace

mixed forecast i.size_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_wishful2_d.gph", replace

mixed forecast i.size_3pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(size_3pts=(0(1)2))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "Small" 1 "Medium" 2 "Large", labsize(vlarge)) ylabel(0 1, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "size_wishful3_d.gph", replace

graph combine size_wishful1_d.gph size_wishful2_d.gph size_wishful3_d.gph, row(1) saving("size_wishful_123_d.gph", replace)

graph display, ysize(4) xsize(9)

***************************************************************************************
** Interaction of expertise and margin of victory (Continuous X Continuous interaction)

mixed forecast c.expertise_4pts##c.margin_d i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 || region: || district_name: expertise_4pts || study_id: , mle var

qui margins, at(expertise_4pts=(0 3) margin_d=(0(2)30))

marginsplot, title("") x(margin_d) recastci(rline) ci1opts(lpat(dash) col(red*1.2%30)) ci2opts(lpat(dash) col(green%30)) ylabel(0 1, labsize(large) nogrid angle(horizontal) format(%5.0f)) plot1opts(lcolor(red*1.2) lpattern(solid) msym(none)) plot2opts(lcolor(green) lpattern(solid) msym(none)) xlabel(0 30, labsize(large)) xtitle("Margin of victory", size(large) margin(t=5)) ytitle("Linear prediction", size(large) margin(r=5 b=3)) legend(size(medsmall)) legend(order(3 "No expertise" 4 "High expertise") pos(6) col(2) size(medlarge) symxsize(8) region(lstyle(none))) legend(region(lcolor(white))) legend(off) graphregion(color(white)) saving("expertise_margin_d.gph", replace) // Plot of ideal types

graph display, ysize(4) xsize(5)

* By level of margin

mixed forecast c.expertise_4pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d >= 0 & margin_d <= 5 || region: || district_name: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("Margin ≤ 5", margin(l=9 b=3)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(medlarge)) ylabel(minmax, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_margin1_d.gph", replace

mixed forecast c.expertise_4pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 5 & margin_d <= 10 || region: || district_name: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("5 < Margin ≤ 10", margin(l=9 b=3)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(medlarge)) ylabel(minmax, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_margin2_d.gph", replace

mixed forecast c.expertise_4pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 10 & margin_d <= 15 || region: || district_name: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("10 < Margin ≤ 15", margin(l=9 b=3)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(medlarge)) ylabel(minmax, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_margin3_d.gph", replace

mixed forecast c.expertise_4pts i.wishful_3pts i.postsecondary age2 i.male time if stelec!=1 & margin_d > 15 || region: || district_name: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("Margin > 15", margin(l=9 b=3)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(medlarge)) ylabel(minmax, labsize(medlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(medlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_margin4_d.gph", replace

graph combine expertise_margin1_d.gph expertise_margin2_d.gph expertise_margin3_d.gph expertise_margin4_d.gph, row(2) saving("expertise_margin_1234_d.gph", replace)

* By partisan preference

mixed forecast c.expertise_4pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 1 || region: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("Loser preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(vlarge)) ylabel(minmax, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_wishful1_d.gph", replace

mixed forecast c.expertise_4pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 2 || region: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("No preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(vlarge)) ylabel(minmax, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_wishful2_d.gph", replace

mixed forecast c.expertise_4pts i.postsecondary age2 i.male time margin_d if stelec!=1 & wishful_3pts == 3 || region: || study_id: , mle var

margins, at(expertise_4pts=(0(1)3))
mplotoffset, offset(0.1) title("Winner preference", margin(l=9 b=3) size(vlarge)) xtitle("") xlabel(0 "None" 1 "Low" 2 "Medium" 3 "High", labsize(vlarge)) ylabel(minmax, labsize(vlarge) format(%3.0f) angle(horizontal)) ytitle("Linear prediction", size(vlarge)) recast(scatter) plotopts(mcolor(black)) ciopt(color(black))

graph display, ysize(5) xsize(5)

graph save "expertise_wishful3_d.gph", replace

graph combine expertise_wishful1_d.gph expertise_wishful2_d.gph expertise_wishful3_d.gph, row(1) saving("expertise_wishful_123_d.gph", replace)

graph display, ysize(4) xsize(9)


******************************************************
** INTERACTIONS BETWEEN NETWORK VARIABLES: DISTRICT **
******************************************************

* Discussion × Disagreement interaction

mixed forecast i.discussion_3pts##i.disagreement_3pts i.wishful_3pts i.postsecondary age2 i.male margin_d time if stelec!=1 || region: || district_name: || study_id: , mle var

qui margins, at(disagreement_3pts=(0 2) discussion_3pts=(0(1)2))

marginsplot, x(discussion_3pts) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0 "Low" 1 "Medium" 2 "High", labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Discussion frequency", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Low disagreement" 4 "High disagreement")) title("(a) Discussion × Disagreement", size(vlarge) margin(b=3 l=12)) saving("discussion_disagreement_d.gph", replace)

* Discussion × Size interaction

mixed forecast i.discussion_3pts##i.size_3pts i.wishful_3pts i.postsecondary age2 i.male margin_d time if stelec!=1 || region: || district_name: || study_id: , mle var

qui margins, at(size_3pts=(0 2) discussion_3pts=(0(1)2))

marginsplot, x(discussion_3pts) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0 "Low" 1 "Medium" 2 "High", labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Discussion frequency", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Small network" 4 "Large network")) title("(b) Discussion × Size", size(vlarge) margin(b=3 l=12)) saving("discussion_size_d.gph", replace)

* Discussion × Expertise interaction

mixed forecast c.discussion##c.expertise_4pts i.wishful_3pts i.postsecondary age2 i.male margin_d time if stelec!=1 || region: || district_name: || study_id: , mle var

qui margins, at(expertise_4pts=(0 3) discussion=(0(1)7))

marginsplot, x(discussion) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0(1)7, labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Discussion frequency (days/week)", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Low expertise" 4 "High expertise")) title("(c) Discussion × Expertise", size(vlarge) margin(b=3 l=12)) saving("discussion_expertise_d.gph", replace)

* Disagreement × Size interaction

mixed forecast i.disagreement_3pts##i.size_3pts i.wishful_3pts i.postsecondary age2 i.male margin_d time if stelec!=1 || region: || district_name: || study_id: , mle var

qui margins, at(size_3pts=(0 2) disagreement_3pts=(0(1)2))

marginsplot, x(disagreement_3pts) recastci(rline) ci1opts(lpat(dash) col(blue%30)) ci2opts(lpat(dash) col(red*1.2%30)) ylabel(minmax, format(%5.2f) labsize(large) nogrid glcolor(gs10) glpat(dot)) plot1opts(lcolor(blue) mcolor(blue) msymbol(none) lpat(solid)) plot2opts(lcolor(red*1.2) mcolor(red) msymbol(none) lpat(solid)) xlabel(0(1)2, labsize(large) nogrid glcolor(gs10) glpat(dot)) xtitle("Disagreement frequency", size(vlarge) margin(t=5 b=3)) ytitle("Linear prediction", size(vlarge) margin(r=5)) legend(size(large) symxsize(4) region(lwidth(none)) order(3 "Small network" 4 "Large network")) title("(d) Disagreement × Size", size(vlarge) margin(b=3 l=12)) saving("disagreement_size_d.gph", replace)

* Combine graphs

graph combine discussion_disagreement_d.gph discussion_size_d.gph, row(1) saving("interactions_contact_networks_d1.gph", replace)

graph display, ysize(7) xsize(12)

graph combine discussion_expertise_d.gph disagreement_size_d.gph, row(1) saving("interactions_contact_networks_d2.gph", replace)

graph display, ysize(7) xsize(12)

log close